#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->listWidget->addItem("MG卡沙");
    ui->listWidget->addItem("MG卡牛");
    ui->listWidget->addItem("RG海牛");

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_insert_clicked()
{
    const QString& value = ui->lineEdit->text();

    ui->listWidget->addItem(value);
}

void Widget::on_pushButton_delete_clicked()
{
    int row = ui->listWidget->currentRow();
    if (row < 0)
    {
        return;
    }

    ui->listWidget->takeItem(row);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (current != nullptr)
    {
        qDebug() << "当前选中的元素: " << current->text();
    }

    if (previous != nullptr)
    {
        qDebug() << "上次选中的元素: " << previous->text();
    }
}
